Debugging an already-running process

Contents|Index|Previous|Next
Debugging an already-running process

The following documentation discusses processes already running for a program invoked for use with GDB.

attach process-id

This command attaches to a running process—one that was started outside GDB. (info files shows your active targets.) The command takes as argument a process ID. The usual way to find out the `process-id` of a Unix process is with the ps utility, or with the ‘jobs -l’ shell command.
attach does not repeat if you use Return a second time after executing the command.
To use attach, your program must be running in an environment which supports processes; for example, attach does not work for programs on bareboard targets that lack an operating system. You must also have permission to send the process a signal.
When using attach, you should first use the file command to specify the program running in the process and load its symbol table. See Commands to specify files.
The first thing GDB does after arranging to debug the specified process is to stop it. You can examine and modify an attached process with all the GDB commands that are ordinarily available when you start processes with run. You can insert breakpoints; you can step and continue; you can modify storage. If you would rather the process continue running, you may use the continue command after attaching GDB to the process.

detach

When you have finished debugging the attached process, you can use the detach command to release it from GDB control. Detaching the process continues its execution. After the detach command, that process and GDB become completely independent once more, and you are ready to attach another process or start one with run. detach does not repeat if you use the Return key again after executing the command.
If you exit GDB or use the run command while you have an attached process, you kill that process. By default, GDB asks for confirmation if you try to do either of these things; you can control whether or not you need to confirm by using the set confirm command (see Optional warnings and messages).

Top|Contents|Index|Previous|Next